package com.yanqu.road.server.cmd.cookboy;

import com.yanqu.road.entity.activity.cookboy.CookBoyMatchDish;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.cookboy.CookBoyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.cookboy.CrossCookBoyMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.C_CROSS_COOK_BOY_SERVE_FOOD, desc = "小当家第一阶段上食材")
public class CrossServeFoodCmd extends CrossCommand {

    private long userId;
    private int activityId;
    private int no;
    private CookBoyMatchDish cookBoyMatchFood = new CookBoyMatchDish();
    private UserBaseInfo userBaseInfo;
    private CookBoyProto.CookBoyFinishFoodTempMsg tempFood;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CookBoyProto.CrossCookBoyServeReqMsg reqMsg = CookBoyProto.CrossCookBoyServeReqMsg.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        activityId = reqMsg.getActivityId();
        no = reqMsg.getNo();
        userBaseInfo = PlayerBasePb.parseToUserBaseInfo(reqMsg.getPlayerBaseData());
        CrossUserMgr.updateUserBaseInfo(userId,userBaseInfo);
        tempFood = reqMsg.getFinishFood();
        cookBoyMatchFood.setId(tempFood.getId());
        cookBoyMatchFood.setFoodId(tempFood.getFoodId());
        cookBoyMatchFood.setFraction(tempFood.getFraction());
        cookBoyMatchFood.setUserId(userId);
        cookBoyMatchFood.setServerId(serverId);
        cookBoyMatchFood.setTime(((long)tempFood.getTime()) * 1000);
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossCookBoyMgr.serveFood(activityId,no,cookBoyMatchFood,tempFood);
    }

    @Override
    public void sendData() {

    }

}
